package com.spddr.pmos.cxf.tree;

import java.util.Collection;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.spddr.pmos.domain.TreeLevel;

import cn.seqdata.jpa.JpaNamed;
import cn.seqdata.pojo.NamedTreeNode;

public class CheckedTreeNode extends NamedTreeNode {
	private TreeLevel level;
	private Boolean checked;
	private Boolean expanded;
	private Object tag;

	public CheckedTreeNode(JpaNamed<?> object) {
		super(object);
	}

	public CheckedTreeNode(JpaNamed<?> object, boolean container) {
		super(object, container);
	}

	public CheckedTreeNode(JpaNamed<?> object, boolean container, boolean expanded) {
		super(object, container);
		this.expanded = expanded;
	}

	@Override
	public String getClz() {
		return getLevel().name();
	}

	@Override
	public String getIconCls() {
		return StringUtils.isEmpty(getLevel().icon) ? null : "fa-" + getLevel().icon;
	}

	@JsonIgnore
	public TreeLevel getLevel() {
		if (null == level) {
			level = TreeLevel.valueOf(wrapper.getClass());
		}
		return level;
	}

	public void setLevel(TreeLevel level) {
		this.level = level;
	}

	@JsonInclude(Include.NON_NULL)
	public Boolean getChecked() {
		return checked;
	}

	public void setChecked(Boolean checked) {
		this.checked = checked;
	}

	@Override
	public void addNamedChildren(Collection<? extends JpaNamed<?>> children) {
		for (JpaNamed<?> child : children) {
			CheckedTreeNode childNode = new CheckedTreeNode(child);
			addChild(childNode);
		}
	}

	public Boolean getExpanded() {
		return expanded;
	}

	public void setExpanded(Boolean expanded) {
		this.expanded = expanded;
	}

	@JsonInclude(Include.NON_NULL)
	public Object getTag() {
		return tag;
	}

	public void setTag(Object tag) {
		this.tag = tag;
	}
}
